package com.lx.patterns.combination;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Menu
 * @Description: //菜单类
 * @Author: 落雪
 * @CreateDate: 2025/1/26 14:31
 * @UpdateUser: 落雪
 * @UpdateDate: 2025/1/26 14:31
 * @UpdateRemark:
 * @Version: 1.0
 */
public class Menu  extends MenuComponent{

    private List<MenuComponent> menuComponentList;

    public Menu(String name,int level){
        this.level = level;
        this.name = name;
        menuComponentList = new ArrayList<MenuComponent>();
    }

    @Override
    public void add(MenuComponent menuComponent) {
        menuComponentList.add(menuComponent);
    }

    @Override
    public void remove(MenuComponent menuComponent) {
        menuComponentList.remove(menuComponent);
    }

    @Override
    public MenuComponent getChild(int index) {
        return menuComponentList.get(index);
    }

    @Override
    public void print() {
        for (int i = 1; i < level; i++) {
            System.out.print("--");
        }
        System.out.println(name);
        for (MenuComponent menuComponent : menuComponentList) {
            menuComponent.print();
        }

    }
}
